<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      var str = "asdasdSMasdasdasdSMsdgaj";
      //用replace 正则
      function fun(str) {
        return str.replace(/SM/g, "**");
      }
      //2,用indexOf ，判断有没有SM+while循环，当indexOf （SM）！=-1 即存在SM的时候replace一次
      //3.replaceALL("SM","**")
      console.log(fun(str));
    </script>
  </body>
</html>
